package com.maomao.concurrent;

import java.util.concurrent.*;

public class Schedule {
    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
        ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(new Callable(){

            @Override
            public Object call() throws Exception {
                System.out.println("Executed");
                return "Called!";
            }
        },5, TimeUnit.SECONDS);

        try {
            System.out.println("result:"+scheduledFuture.get() );
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        scheduledExecutorService.shutdown();
    }
}
